#include "timer.h"
#include "led.h"

void timer1_init(uint16_t psr,uint16_t arr)
{
    timer_parameter_struct timer1_init_struct;
    rcu_periph_clock_enable(RCU_TIMER1);
    timer_deinit(TIMER1);
    timer1_init_struct.prescaler = psr;
    timer1_init_struct.alignedmode = TIMER_COUNTER_EDGE;
    timer1_init_struct.counterdirection = TIMER_COUNTER_UP;
    timer1_init_struct.period = arr;
    timer1_init_struct.clockdivision = TIMER_CKDIV_DIV1;
    timer1_init_struct.repetitioncounter = 0;
    timer_init(TIMER1,&timer1_init_struct);
    timer_interrupt_enable(TIMER1,TIMER_INT_UP);

    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
    nvic_irq_enable(TIMER1_IRQn,2,2);

    timer_enable(TIMER1);
}
void TIMER1_IRQHandler(void)
{
    timer_interrupt_flag_clear(TIMER1,TIMER_INT_FLAG_UP);
    LED1_Toggle();
}
